<?php

namespace backend\modules\comment\models;

use backend\modules\goods\models\Goods;
use Yii;

/**
 * This is the model class for table "comment".
 *
 * @property string $comment_id
 * @property string $goods_id
 * @property string $attrcat_id
 * @property string $email
 * @property string $user_name
 * @property string $content
 * @property integer $comment_rank
 * @property string $add_time
 * @property string $ip_address
 * @property string $parent_id
 * @property string $user_id
 * @property string $comment_img_id
 * @property integer $is_niming
 * @property integer $is_show
 *
 *
 * @property CommentImages[] $commentImages
 */
class Comment extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'comment';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
//            TimestampBehavior::className(),
            // 名为myBehavior4的行为，也是给出了MyBehavior类的配置数组
            'uuid' => [
                'class' => \common\behavior\uuidBehavior::className(),
                'owner' => $this
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['comment_id','default','value'=>$this->getUUID()],
            [['comment_id', 'goods_id', 'content'], 'required'],
            [['content'], 'string'],
            [['comment_rank', 'add_time', 'is_niming','is_show'], 'integer'],
            [['comment_id', 'goods_id', 'attrcat_id', 'parent_id', 'user_id', 'comment_img_id'], 'string', 'max' => 40],
            [['email', 'user_name'], 'string', 'max' => 60],
            [['ip_address'], 'string', 'max' => 15],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'comment_id' => Yii::t('app', 'Comment ID'),
            'goods_id' => Yii::t('app', '评论的商品'),
            'attrcat_id' => Yii::t('app', '评论的商品类型'),
            'email' => Yii::t('app', 'Email'),
            'user_name' => Yii::t('app', '评论人姓名'),
            'content' => Yii::t('app', '评论内容'),
            'comment_rank' => Yii::t('app', '评价级别'),
            'add_time' => Yii::t('app', '评论时间'),
            'ip_address' => Yii::t('app', '评论IP地址'),
            'parent_id' => Yii::t('app', '回复的上条评论'),
            'user_id' => Yii::t('app', '评论人ID'),
            'comment_img_id' => Yii::t('app', 'Comment Img ID'),
            'is_niming' => Yii::t('app', '是否匿名'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCommentImages()
    {
        return $this->hasMany(CommentImages::className(), ['comment_id' => 'comment_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGoods()
    {
        return $this->hasMany(Goods::className(), ['goods_id' => 'goods_id']);
    }

    /**
     * @inheritdoc
     * @return \backend\modules\comment\models\query\CommentQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \backend\modules\comment\models\query\CommentQuery(get_called_class());
    }
}
